// components/bind_account.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    wxPhone:{
      type:String,
      value:''
    },
    isShow:{
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    time:45,
    smscode:''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    closeMask(){
      this.setData({
        isShow:false
      });
    },
    setPhone(e){
      this.setData({
        wxPhone: e.detail.value
      });
    },
    setSmscode(e){
      this.setData({
        smscode: e.detail.value
      });
    },
    _getSmsCode(){
      let me=this;
      if(!me.data.wxPhone){
        wx.showToast({
          icon: 'none',
          title: '请输入手机号',
        })
        return;
      }
      if (me.data.time < 45){
        return;
      }
      me.timeInterval = setInterval(()=>{
        me.data.time--;
        me.setData({
          time:me.data.time
        });
        if(me.data.time == 1){
          clearInterval(me.timeInterval);
          me.setData({
            time:45
          });
        }
      },1000);
      this.triggerEvent("getSmsCode", me.data.wxPhone);
    },
    _getPhoneNumber(e){
      this.triggerEvent("getPhoneNumber",e.detail);
    },
    _bindAccount(e){
      this.triggerEvent("bindAccount", { 
        phone:this.data.wxPhone,
        smscode: this.data.smscode
      });
    }
  }
})
